<template>
  <div class="dialog-form">
    <el-form :model="form" ref="formRef">
      <el-form-item>
        <span class="form-title">{{ form.title }}</span>
      </el-form-item>
      <el-form-item v-for="(item, index) in form.formData" :key="index" label-width="100px">
        <div class="form-item">
          <div class="title">
            <label class="form-item-label " slot="label">{{ item.label }}</label>
          </div>
          <div class="content">
            <el-switch v-model="item.value" active-color="#13ce66" inactive-color="#ff4949" active-value="1"
              inactive-value="0" v-if="item.type==='switch'" @change="submitForm(item.function, item, form.formData)">
            </el-switch>

            <el-input v-model="item.value" v-if="item.type==='input'" @blur="submitForm(item.function, item, form.formData)">
            </el-input>

            <span class="form-item-span" v-if="item.type==='text'">
              {{ item.value }}
            </span>

            <el-select class="utlis-btn-width" v-model="item.value" :placeholder="item.label" v-if="item.type==='select'" @change="submitForm(item.function, item, form.formData)">
              <el-option v-for="option in item.option" :key="option.value" :label="option.label" :value="option.value">
              </el-option>
            </el-select>

            <el-slider v-model="item.value" show-input v-if="item.type==='slider'" :step="item.option.step" :max="item.option.max"
              :min="item.option.min" @change="submitForm(item.function, item)">
            </el-slider>

            <el-button v-if="item.type==='button'" @click="submitForm(item.function, item, form.formData)">
              {{ item.value }}
            </el-button>
          </div>
        </div>


      </el-form-item>
      <el-form-item>
        <el-button @click="formChange()" type="danger" plain>关闭</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    props: ['form', 'submitForm', 'formChange']
  }
</script>

<style lang="less" scoped>
  .utils-label {
    // width: 30%;
    // width: 50px;

  }

  .form-title {
    padding: 0;
  }
  .form-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    padding: 10px 20px;
    .title {

    }
    .content {
      width: 150px;
      display: flex;
      justify-content: flex-end;
      .utlis-btn-width {
        width: 200px;
      }
    }

  }
  .utils-content {
    width: 70%;
  }

  /deep/ .el-form-item__content {
    margin-left: 0 !important;
  }

  .el-form {
    padding: 5px;

    .el-form-item {
      margin-bottom: 0;
      // padding: 0 0 8px 0;
      // display: flex;
      // justify-content: space-between;
      width: 100%;

      .form-title {
        font-size: large;
        font-weight: bold;
        color: aqua;
        // padding: 20px 0 0 0;
      }

      .form-item-label {
        color: aqua;
        width: 30%;
        text-align: right;
        // padding: 0 20px 0 40px;
      }



      .el-input {
        width: 220px;
      }

      .form-item-span {
        color: aquamarine;
      }

      .el-select {
        width: 120px;
      }
    }
  }
</style>
